﻿(function () {

    // Establish the root object, `window` in the browser, or `global` on the server.
    var root = this;

    // Load the 3rd party libraries
    
    // Load our app/custom plug-ins and bootstrap the app
    requirejs.config(
        {
            // Let require.js load all app/custom modules asynchronously as needed.
            // They are all in this folder.
            // If we bundle this foler, this is not needed. But if we don't bundle, we need this.
            baseUrl: CONSTANST.appUrl + 'Scripts/app', /* script default location */

            // List paths to js files that are not in the baseUrl and not in bundles.
            // If we use the non-amd versions of 3rd libs we can bundle them instead.
            // In which case we don;t need the paths.
            // Example:
            paths: {
                'trafficcop': '../TrafficCop-amd.min',
                'infuser': '../infuser-amd.min',
                'koExternalTemplateEngine-amd.min': '../koExternalTemplateEngine-amd.min',
            //    'infuser': '../koExternalTemplateEngine-amd.js',
            }
        }
    );

    registerNonAmdLibs();

    function registerNonAmdLibs() {
       
        define('jquery', [], function () { return root.jQuery; });
        define('ko', [], function () { return root.ko; });
        //define('komapping', [], function () { return root.ko.mapping; });
        //define('kovalidation', [], function () { return root.ko.validation; });
        define('moment', [], function () { return root.moment; });
        define('literals', [], function () {
            var literals = root.literals || {};
            return literals;
        });
    }

    requirejs(
        [
            'koExternalTemplateEngine-amd.min'
        ],
        boot);
    
    function boot() {
        // Start-up the app, now that all prerequisites are in place.

        if (typeof Object.create !== 'function') {
            //console.log('Object.create');
            Object.create = function (o) {
                var F = function () { };
                F.prototype = o;
                return new F();
            };
        }

        Function.prototype.method = function (name, func) {
            if (!this.prototype[name]) {
                this.prototype[name] = func;
                return this;
            }
        };
    }
})();